package cc.telecomdigital.tdstock.Http;

import java.util.Map;
import java.util.TreeMap;

public enum H_CODE
{
	OK,
	NO_NETWORK,
	SOKET_TIME_OUT,
	CONNECTION_TIME_OUT,
	SESSION_EXPIRED,
	IO_EXCEPTION,
	HTTP_404,
	HTTP_NONE,
	SYSTEM_BUSY,
	UNKNOW,
	NONE;
	
	private  int    seqId;
	private  static Map<Integer, H_CODE> enumMap = new TreeMap<Integer, H_CODE>();
	private  static final int START_VALUE = 0;

	static
	{
		for(int i=0;i < values().length;i++)
		{
			values()[i].seqId = START_VALUE + i;
			enumMap.put(values()[i].seqId, values()[i]);
		}
	}

	public int getId()
	{
		return seqId;
	}

	static private H_CODE FromIndex(int iIndex)
	{
		return enumMap.get(iIndex);
	}
	

	/** Convert the ecCode into a readable information
	 * @param isChinese - translate as Chinese if it is set to true
	 * @return a informable string;
	 */	
	public String ToString()
	{
		int iLanguage;
		
		iLanguage = 1;
		
		return ecCodeString[seqId][iLanguage];
	}

	private static final String[][] ecCodeString = {
		    {"OK", 				  		"沒有錯誤"},

		    {"Network is unavailable",	"尚未連接數據網絡" },
		    {"Socket time out",      	"請求連接超時"},
		    {"Connection time out",  	"網絡連接超時"},
		    {"Session expired",    		"會話已超時"},
		    {"Io exception",       		"網絡連接異常"},
		    
		    {"http 404", 				"服務請求異常"},
		    {"http none",     			"找不到此服務"},
		    {"System is busy. Please try again later", "系統繁忙。請稍後再試"},
		    {"Unknown",          		"不知明的錯誤"},
		    {"None",          			""}
		  };
}
